

function downloadTxt(filename, text) {
    var pom = document.createElement('a');
    pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    pom.setAttribute('download', filename);
    if (document.createEvent) {
        var event = document.createEvent('MouseEvents');
        event.initEvent('click', true, true);
        pom.dispatchEvent(event);
    } else {
        pom.click();
    }
}



function downloadPage() {
    // https://blog.csdn.net/weixin_42649856/article/details/104325029
    // console.log(document.);
    //  console.log(document.getElementsByTagName('html')[0].outerHTML);
    // downloadTxt("pta.html",document.getElementsByTagName('html')[0].outerHTML);
    let htmlDom = document.getElementsByTagName("html")[0];
    // console.log(htmlDom);
    let title;
    try{
         title = document.getElementById("pageTitleText").textContent;
        title = title.trim();
    }catch (e) {
         title = htmlDom.getElementsByClassName("mb-2 card-header")[0].textContent;
    }


    title = to_file_path_name(title);
    // htmlDom = removeAllScript(htmlDom);
    let htmlTxt = stripScripts(htmlDom).outerHTML;
    // console.log(htmlDom);
    // console.log(htmlDom.outerHTML);
    // 获得文本的html
    // let body = htmlDom.outerHTML;
    // let body = document.getElementsByTagName('html')[0].outerHTML;
    // console.log(body);
    // let htmlTxt = removeDontWant(htmlDom.outerHTML);
    // let htmlTxt = removeDontWant(htmlDom);
    // console.log(htmlDom.outerHTML);
    // console.log(htmlDom);
    downloadTxt(title+".html", htmlTxt);
}

// downloadPage();